package com.wlyuan.open.remote.facade;

import com.alibaba.fastjson.JSON;
import com.wlyuan.basic.api.IConsigneeService;
import com.wlyuan.basic.dto.consignee.ConsigneeCreationDTO;
import com.wlyuan.basic.dto.consignee.ConsigneeDetailDTO;
import com.wlyuan.open.domain.source.dispatcher.consignee.CreateConsignee;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yuanjie
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class ConsigneeFacade {
    @Resource
    private IConsigneeService consigneeService;

    public ConsigneeDetailDTO createConsignee(CreateConsignee createConsignee) {
        var creation = new ConsigneeCreationDTO();
        if (StringUtils.isBlank(createConsignee.getContactMobile())) {
            createConsignee.setContactMobile("-");
        }
        BeanUtils.copyProperties(createConsignee, creation);
        logger.info("创建收货方：{},{}", JSON.toJSON(createConsignee), JSON.toJSON(creation));
        return consigneeService.createShould(creation);

    }
}
